package com.leung.auth;

import cn.dev33.satoken.interceptor.SaInterceptor;
import cn.dev33.satoken.router.SaRouter;
import cn.dev33.satoken.stp.StpUtil;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class SaTokenConfigure implements WebMvcConfigurer {
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		//开启注解鉴权功能
		registry.addInterceptor(new SaInterceptor(handle -> SaRouter.match("/**", "/user/doLogin", r -> StpUtil.checkLogin()))).addPathPatterns("/**");
	}

	/**
	 * 基于过滤器的拦截 一般用在分布式鉴权网关
	 */
//	@Bean
//	public SaServletFilter saServletFilter() {
//		//指定 [ 拦截路由 ] 与 [ 放行路由 ]
//		return new SaServletFilter().addInclude("/**").addExclude("/user/**");
//	}
}